﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace GUILib
{
    public class ViewModelBase : INotifyPropertyChanged
    {
        CommandHolder _commandHolder = new CommandHolder();

        public event PropertyChangedEventHandler PropertyChanged;

        protected void InvokePropertyChanged(PropertyChangedEventArgs e)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected void InvokePropertyChanged<T>(Expression<Func<T>> propertyExpression)
        {
            var propertyName = SymbolHelpers.GetPropertyName(propertyExpression);
            InvokePropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }


        protected CommandHolder Commands
        {
            get
            {
                return (_commandHolder ?? (_commandHolder = new CommandHolder()));
            }
        }
    }
}
